<template>
	<view class="wocomplete">
		<view class="ag-topbg"></view>
		<view class="wocomplete-card">
			<view class="wocomplete-card__head">
				<view class="ag-womarker">{{firstChar(orderDetailData.WoType)}}</view>
				<view class="wocomplete-card__col">
					<view class="wocomplete-card__col-row">
						<text class="wocomplete-card__name">{{orderDetailData.WoType}}</text>
						<view class="wocomplete-card__no">{{orderDetailData.WoNum}}</view>
					</view>
					<view class="wocomplete-card__col-time" v-if="false">
						<text>时间1：2017-3-21 15:19</text>
						<text>时间2：2017-3-21 15:19</text>
					</view>
				</view>
			</view>

			<!-- 保养换芯工单完工 -->
			<view v-if="true" class="wocomplete-card__body">
				<textarea class="wocomplete-card__remark" placeholder="完工备注" :value="OrderRremark" @input="onChangeOrderRremark"></textarea>
				<AGInput icon="calender" readonly placeholder="客户要求保养日期" @openCalender="onOpenAccoountClaimDate" :value="CustomerRequiresMaintenanceDate" />
				<uni-calendar ref="AccoountClaimDate" :insert="false" :lunar="true" :start-date="'2019-3-2'" @confirm="confirmAccoountClaimDate" />
				<view class="wocomplete-card__content1" v-for="(productItem , index) in orderDetailData.WoProuduct" :key="productItem.WoObjectId">
					<!-- 一行两个 -->
					<view class="ag-cell">
						<view class="ag-cell__label">
							<text>产品编码：</text>
						</view>
						<view class="ag-cell__value">
							<text>{{productItem.ProductNum}}</text>
						</view>
					</view>
					<view class="ag-cell">
						<view class="ag-cell__label">
							<text>产品类型：</text>
						</view>
						<view class="ag-cell__value">
							<text>{{productItem.ProdTypeGroup}}</text>
						</view>
					</view>
					<!-- 一行一个 -->
					<view class="ag-cell">
						<view class="ag-cell__label">
							<text>产品名称：</text>
						</view>
						<view class="ag-cell__value">
							<text>{{productItem.ProductName}}</text>
						</view>
					</view>
					<view class="ag-cell">
						<view class="ag-cell__label">
							<text>保修开始时间：</text>
						</view>
						<view class="ag-cell__value">
							<text>{{productItem.WarrantyStartDate}}</text>
						</view>
					</view>
					<view class="ag-cell">
						<view class="ag-cell__label">
							<text>保修结束时间：</text>
						</view>
						<view class="ag-cell__value">
							<text>{{productItem.WarrantyEndDate}}</text>
						</view>
					</view>
					<view class="ag-cell">
						<view class="ag-cell__label">
							<text>安装位置：</text>
						</view>
						<view class="ag-cell__value">
							<text>{{productItem.InstallLocation||""}}</text>
						</view>
					</view>
					<view class="ag-cell">
						<view class="ag-cell__label">
							<text>购机来源：</text>
						</view>
						<view class="ag-cell__value">
							<text>{{productItem.PurchaseSourceText||""}}</text>
						</view>
					</view>
					<view class="ag-cell">
						<view class="ag-cell__label">
							<text>购机卖场名称：</text>
						</view>
						<view class="ag-cell__value">
							<text>{{orderDetailData.PurchaseChanel}}</text>
						</view>
					</view>
					<view class="ag-cell" v-if="productItem.ProductImage">
						<view class="ag-cell__value">
							<image mode="aspectFill" class="img-prod" :src="getImage(productItem.ProductImage)" />
						</view>
					</view>
					<view class="ag-cellgroup">
						<view class="ag-cell">
							<view class="ag-cell__label">
								<text>物流码：</text>
							</view>
							<view class="ag-cell__value">
								<text>{{productItem.Barcode||""}}</text>
							</view>
						</view>
						<view class="ag-cell">
							<view class="ag-cell__label">
								<text>物流码有效性：</text>
							</view>
							<view class="ag-cell__value">
								<text>{{productItem.IsSerialValid||""}}</text>
							</view>
						</view>
					</view>
					<AGInput icon="qrcode" placeholder="物流码" @openQrcode="onOpenQrcode(index, $event)" :value="productItem.Barcode"
					 :disabled="productItem.IsProductConfirmed" @onBlur="onBlurLogisticsCode(index,$event)" data-index="" />
					<AGInput icon="search" placeholder="产品" @openSearch="onOpenSearch(index)" :value="productItem.ProductNum"
					 :disabled="productItem.isDisplayProdInputField" />
					<AGInput icon="calender" placeholder="保修开始时间" @openCalender="onOpenPurchaseDate(index, e)" :value="productItem.PurchaseDate | GetDate"
					 :disabled="productItem.IsProductConfirmed" />
					<uni-calendar ref="PurchaseDate" :insert="false" :lunar="true" :start-date="'2019-3-2'" @confirm="confirmPurchaseDate(index,$event)" />
					<button class="cu-btn lg primary block" @click="onAffirmProduct(index)">确认产品</button>
					<!-- 保养换芯信息 用于保养换芯工单完工 -->
					<view class="core">
						<view class="wocomplete-fix-row">
							<text>保养方式：</text>
							<picker mode="selector" :range="MaintenanceMethod" range-key="text" :value="productItem.maintenanceIndex"
							 @change="ChangeMaintenance(index,$event)">
								<AGInput customStyle="margin-top:0px;" readonly dropdown placeholder="保养方式" :value="MaintenanceMethod[productItem.maintenanceIndex].text" />
							</picker>
						</view>
						<view class="core-head">
							<text class="core-head__title">保养换芯信息</text>
							<view class="core-head__btn" @click="BatchChangeCore(index)">
								<text>批量扫描换芯</text>
								<image src="../../../static/img/icon-qrcode-color.png" />
							</view>
						</view>
						<view class="core-list">
							<view class="core-item" v-for="(maintenanceItem , mindex) in productMaintainData[index]" :key="maintenanceItem.FilterTypeId">
								<view class="core-item__label">
									{{maintenanceItem.FilterPartTypeName}}
								</view>
								<view class="core-item__value" :style="maintenanceItem.IsReplaceFilterPart?'background-color: #FCA033;':'background-color: #3d85db;'">
									<text>已使用：{{maintenanceItem.FilterPartUsedCost}}</text>
									<text>剩余：{{maintenanceItem.FilterPartUnUsedCost}}</text>
									<text v-if="maintenanceItem.IsReplaceFilterPart">￥{{maintenanceItem.FilterPartPrice}}</text>
								</view>
								<switch color="#3d85db" @change="changeCore(mindex,index)" :checked="maintenanceItem.IsReplaceFilterPart"></switch>
							</view>
							<view v-if="productMaintainData[index]==null?true:false">没有查找到产品关联的滤芯保养行记录，请填写购机日期或点击批量扫描换芯添加！</view>
						</view>
						<view class="core-footer">
							<view class="core-footer__head">
								<text>更换配件数量：{{productItem.MaintainPartCount}}</text>
								<text>保外配件费用: {{productItem.MaintainPartAmount}}</text>
							</view>

						</view>
					</view>
					<!-- 水质检测 -->
					<view class="repair" v-if="productItem.IsRequired">
						<view class="repair-head">
							<text class="repair-head__title">水质检测信息</text>
							<image v-if="productItem.isShowWaterAnalysisAddBtn" class="repair-head__add" src="../../../static/img/icon-add.png"
							 @click="onOpenWaterQualityPopup(index,$event)" />
						</view>
						<view class="repair-list" v-if="!productItem.isShowWaterAnalysisAddBtn">
							<view class="repair-item">
								<view class="repair-item__head">
									<text class="repair-item__head-title">水质检测结果</text>
									<image v-if="!productItem.isShowWaterAnalysisAddBtn" class="repair-item__head-edit" src="../../../static/img/icon-edit.png"
									 @click="onOpenWaterQualityPopup(index,$event)" />
									<image v-if="!productItem.isShowWaterAnalysisAddBtn" class="repair-item__head-del" src="../../../static/img/icon-close.png"
									 @click="onCanleWaterQuality(index)" />
								</view>
								<view class="repair-item__body">
									<view class="ag-cell">
										<view class="ag-cell__label">
											<text>原水TDS：</text>
										</view>
										<view class="ag-cell__value">
											<text>{{productItem.OriTDS}}</text>
										</view>
									</view>
									<view class="ag-cell">
										<view class="ag-cell__label">
											<text>原水水温：</text>
										</view>
										<view class="ag-cell__value">
											<text>{{productItem.OriTemperature}}</text>
										</view>
									</view>
									<view class="ag-cell">
										<view class="ag-cell__label">
											<text>原水硬度：</text>
										</view>
										<view class="ag-cell__value">
											<text>{{productItem.OriHardness}}</text>
										</view>
									</view>
									<view class="ag-cell">
										<view class="ag-cell__label">
											<text>原水余氯：</text>
										</view>
										<view class="ag-cell__value">
											<text>{{productItem.OriChlorine}}</text>
										</view>
									</view>
									<view class="ag-cell">
										<view class="ag-cell__label">
											<text>纯水TDS：</text>
										</view>
										<view class="ag-cell__value">
											<text>{{productItem.NewTDS}}</text>
										</view>
									</view>
									<view class="ag-cell">
										<view class="ag-cell__label">
											<text>软化后硬度：</text>
										</view>
										<view class="ag-cell__value">
											<text>{{productItem.NewHardness}}</text>
										</view>
									</view>
									<view class="ag-cell">
										<view class="ag-cell__label">
											<text>净化余氯：</text>
										</view>
										<view class="ag-cell__value">
											<text>{{productItem.NewChlorine}}</text>
										</view>
									</view>
									<view class="ag-cell">
										<view class="ag-cell__label">
											<text>检测确认：</text>
										</view>
										<view class="ag-cell__value">
											<text>{{productItem.IsWaterAnalysis?"是":"否"}}</text>
										</view>
									</view>
									<view class="ag-cell">
										<view class="ag-cell__label">
											<text>是否必须水质检测：</text>
										</view>
										<view class="ag-cell__value">
											<text>{{productItem.IsRequired?"是":"否"}}</text>
										</view>
									</view>
								</view>
							</view>
						</view>
						<view class="repair-footer">
						</view>
						<waterQuality ref="waterQuality" :proItem="productItem" :fieldReq="ParseWaterAnalysisFieldRequired(productItem.WaterAnalysisFieldRequired)"
						 @onSaveWaterQuality="saveWaterQuality(index,$event)" />
					</view>
				</view>
				<!-- <AGInput @click="onQrcodeSelect" icon="qrcode" readonly placeholder="物流码" /> -->
				<!-- <AGInput @click="onCalenderSelect" icon="calender" readonly placeholder="购机日期" /> -->

			</view>
			<view class="wocomplete-fix-row" v-if="isShowActualReceiptAmountField">
				<text style="margin-left: 60rpx;">实际收款总金额：</text>
				<AGInput placeholder="实际收款总金额（保内工单不显示）" :value="ActualReceiptAmount" @change="onChangeActualReceiptAmount" width="30rpx" />
			</view>
		<!-- 	<AGInput v-if="isShowActualReceiptAmountField" type="number" placeholder="实际收款总金额（保内工单不显示）" :value="ActualReceiptAmount"
			 @change="onChangeActualReceiptAmount" /> -->
		</view>
		<view class="wocomplete-section">
			<view class="wocomplete-section__head">
				<view>现场图片</view>
				<text @click="navToUploadImg">查看全部</text>
			</view>
			<scroll-view :scroll-x="true" class="wocomplete-listimage">
				<view class="wocomplete-listimage__inner">
					<image class="wocomplete-listimage__item" v-for="(picItem, picIndex) in orderDetailData.WoItemPicture" :key="picIndex"
					 :src="getImageBase64(picItem)" @tap="navToUploadImg" />
					<navigator url="../../woupload/index" v-if="!orderDetailData.WoItemPicture"><text class="cuIcon-upload">上传图片</text></navigator>
				</view>
			</scroll-view>
		</view>
		<view class="wocomplete-section">
			<view class="wocomplete-section__head">
				<view>完工处理状态</view>
				<!-- <text >查看全部</text> -->
			</view>
			<view class="wocomplete-listprocess">
				<view class="wocomplete-listprocess__item">
					<text class="wocomplete-listprocess__title">数据同步：{{orderDetailData.DataSyncStateName}}</text>
					<text class="wocomplete-listprocess__desc">{{orderDetailData.DataSyncInfo}}</text>
				</view>
				<view class="wocomplete-listprocess__divider"></view>
				<view class="wocomplete-listprocess__item">
					<text class="wocomplete-listprocess__title">完工处理：{{orderDetailData.FinishedHandleStateName}}</text>
					<text class="wocomplete-listprocess__desc">{{orderDetailData.FinishHandleInfo}}</text>
				</view>
			</view>
		</view>
		<view class="wocomplete-footer">
			<button class="cu-btn lg primary block plain" @click="onCancel">取消</button>
			<button class="cu-btn lg primary block" @click="onSumbit">提交</button>
		</view>
	</view>
</template>

<script>
	import AGInput from '@/components/AGInput';
	import uniCalendar from '@dcloudio/uni-ui/lib/uni-calendar/uni-calendar.vue'
	import guaranteebehavior from './guaranteebehavior'
	import waterQuality from "@/components/WaterQualityPopup"
	import Utils from '../../../common/utils';
	export default {
		mixins: [guaranteebehavior],
		components: {
			AGInput,
			uniCalendar,
			waterQuality,
		},
		filters: {
			//获取日期
			GetDate(value) {
				if (value) {
					var date = value.replace(/-/g, '/')
					let result = Utils.formatDate(new Date(date), 'yyyy/MM/dd');
					return result;
				}
				return '';
			},
		},
		watch: {
			'orderDetailData': {
				handler(newval, oldval) {
					if (newval.hasOwnProperty("WoProuduct") &&
						newval.WoProuduct.length > 0) {
						this.initData(newval);
						for (let index in this.orderDetailData.WoProuduct) {
							let itemPro = newval.WoProuduct[index]
							itemPro.MaintainPartCount = 0;
							itemPro.MaintainPartAmount = 0;
							if (itemPro.PurchaseDate) {
								//接口如果有返回保养列表的缓存数据，则不需要调用接口
								if (itemPro.ProductMaintainData) {
									this.productMaintainData.splice(index, 1, itemPro.ProductMaintainData);
									this.AggregateMaintainPartData(itemPro);
								} else {
									this.GetMaintainInfoFromServer(itemPro, index);
								}
								//console.log(itemPro)
								// this.GetProductMaintainInfo(itemPro.PurchaseDate, itemPro.CustProductId,
								// 	itemPro.IsProductConfirmed, itemPro.ProuctId).then((ProductMaintainData) => {
								// 	itemPro.ProductMaintainData = ProductMaintainData;
								// 	itemPro.MaintainPartCount = 0;
								// 	itemPro.MaintainPartAmount = 0;
								// 	this.productMaintainData.push(itemPro.ProductMaintainData);
								// }, (err) => {
								// 	console.log(err);
								// });
							}
						}
						console.log(this.productMaintainData);
					}
				}
			},
		},
		computed: {
			// maintainColor(){
			// 	if()
			// },
		},
		data() {
			return {
				orderDetailData: {},
				orderDetailId: "",
				CustomerRequiresMaintenanceDate: "",
				isShowActualReceiptAmountField: false,
				productMaintainData: [],
				maintainColor: 'background-color: #EE1111;',
				OrderRremark: "",
				ActualReceiptAmount: "",
			}
		},
		onLoad: function(Option) {
			this.orderDetailId = Option.orderDetailId;
			//上传图片后刷新
			uni.$on('reLoadInstall', () => {
				this.GetOrderDataImg().then((succ) => {
					this.orderDetailData.WoItemPicture = succ;
				}, (err) => {
					console.log(err);
				})
			})

			//选择产品后刷新
			uni.$on('selectProdItem', (e) => {
				//console.log(e.prodItem,e.prodIndex);
				let upProdItem = this.orderDetailData.WoProuduct[e.prodIndex];
				console.log(e.prodItem, upProdItem);
				let selectProdItem = e.prodItem;
				upProdItem.ProductNum = selectProdItem.Name;
				upProdItem.ProductName = selectProdItem.ProductNumber;
				upProdItem.ProuctId = selectProdItem.ProductId;
				upProdItem.ProdTypeGroup = selectProdItem.ProductTypeName;
				upProdItem.WaterAnalysisFieldRequired = selectProdItem.WaterAnalysisFieldRequired;
				upProdItem.FaultyGroup = selectProdItem.proFaultyGroup;
				upProdItem.FaultyGroupName = selectProdItem.proFaultyGroupName;
				upProdItem.ProductImage = e.proImage;
				//更新保养信息
				this.GetMaintainInfoFromServer(upProdItem, e.prodIndex);
				//console.log(selectProdItem.WaterAnalysisFieldRequired, upProdItem.WaterAnalysisFieldRequired)
			})
			//取消更换保养滤芯
			uni.$on('onCancel', (e) => {
				//let proMian = this.productMaintainData[e.proIndex];
				let itemPro = this.orderDetailData.WoProuduct[e.proIndex];
				let MianList = itemPro.ProductMaintainData[e.mindex];
				MianList.IsReplaceFilterPart = e.IsReplaceFilterPart;
				//itemPro.ProductMaintainData = proMian;
				this.productMaintainData.splice(e.proIndex, 1, itemPro.ProductMaintainData);
			});
			//更换保养滤芯
			uni.$on('onConfirm', (e) => {
				//let proMian = this.productMaintainData[e.proIndex];
				let itemPro = this.orderDetailData.WoProuduct[e.proIndex];
				let MianItem = itemPro.ProductMaintainData[e.mindex];
				let maintainItem = e.maintainItem;
				MianItem.FilterPartTypeName = maintainItem.AppBrief;
				MianItem.FilterPartTypeID = maintainItem.FilterTypeId;
				MianItem.FilterPartID = maintainItem.PartsGuid;
				MianItem.FilterPartNum = maintainItem.PartsNum;
				MianItem.FilterPartName = maintainItem.PartsName;
				MianItem.FilterPartPrice = maintainItem.Price;
				MianItem.FilterPartInventory = maintainItem.SiteStock;
				MianItem.FilterPartMaintainPeriod = maintainItem.MaintainPeriod;
				MianItem.IsReplaceFilterPart = true;
				MianItem.IsReplacePurchasedByOneself = maintainItem.IsReplacePurchasedByOneself;
				console.log(MianItem);
				this.productMaintainData.splice(e.proIndex, 1, itemPro.ProductMaintainData);
				this.AggregateMaintainPartData(itemPro)
			});
			//批量添加保养滤芯
			uni.$on('onBatchConfirm', (e) => {
				this.BindMaintainList(e.MaintainList, e.proIndex);
			});

			this.onLoadData();
		},
		onUnload() {
			uni.$off("reLoadInstall");
			uni.$off("selectProdItem");
			uni.$off('onCancel');
			uni.$off('onConfirm');
			uni.$off('onBatchConfirm');
		},
		methods: {
			onLoadData() {
				uni.showLoading({
					title: "加载中",
					mask: true,
				});
				this.GetOrderData();
				// this.GetProductMaintainInfo();
			},
			formatDate(data) {
				if (data) {
					debugger
					var format = data.replace(/-/g, '/')
					var timestamp = utils.formatDate(new Date(format), "yyyy/MM/dd");
					return timestamp;
					// return utils.formatDate(new Date(datestr), fmt);
				}
				return '';
			},

			navToUploadImg(e) {
				uni.navigateTo({
					url: "../../woupload/index"
				})
			},
			BatchChangeCore(index) {
				uni.navigateTo({
					url: "../../batchchangecore/index?WoId=" + this.orderDetailId + "&proIndex=" + index
				})
			},
			changeCore(mindex, proIndex) {
				let woProItem = this.orderDetailData.WoProuduct[proIndex];
				let maintainItem = woProItem.ProductMaintainData[mindex]
				//let maintainItem = mainPartList[mindex];
				console.log(maintainItem);
				let PartsNum = maintainItem.FilterPartNum;
				let WoId = this.orderDetailId;
				maintainItem.IsReplaceFilterPart = !maintainItem.IsReplaceFilterPart;
				// let IsDisabledReplacePurchasedByOneself = maintainItem.IsDisabledReplacePurchasedByOneself;
				// let IsReplacePurchasedByOneself = maintainItem.IsReplacePurchasedByOneself;
				//let result = JSON.stringify(maintainItem);
				if (maintainItem.IsReplaceFilterPart && !maintainItem.IsNewAddRow) {
					let retCheck = this.CheckAddMaintainInfo(woProItem);
					if (retCheck) {
						//AddMaintainInfo(woProItem, maintainItem, false);
						// uni.navigateTo({
						// 	url: '../../changecore/index?mindex=' + mindex +"&proIndex="+proIndex+"&WoId="+WoId+"",
						// });	
						let parm = {
							mindex: mindex,
							proIndex: proIndex,
							WoId: WoId,
							PartsNum: maintainItem.FilterPartNum,
							IsDisabledReplacePurchasedByOneself: maintainItem.IsDisabledReplacePurchasedByOneself,
							IsReplacePurchasedByOneself: maintainItem.IsReplacePurchasedByOneself,
						}
						let result = JSON.stringify(parm);
						uni.navigateTo({
							url: '../../changecore/index?parm=' + encodeURIComponent(result)
						});
					} else {
						maintainItem.IsReplaceFilterPart = false;
					}
				} else {
					if (maintainItem.IsNewAddRow) {
						uni.showModal({
							title: "操作确认",
							content: "确认取消更换滤芯？",
							success: (res) => {
								if (res.confirm) {
									//let mainPart = this.productMaintainData[ProIndex]
									woProItem.ProductMaintainData.splice(mindex, 1);
								}
								this.AggregateMaintainPartData(woProItem);
							}
						});
					} else {
						uni.showModal({
							title: "操作确认",
							content: "确认取消更换滤芯？",
							success: (res) => {
								if (res.confirm) {
									maintainItem.FilterPartTypeName = maintainItem.HisFilterPartTypeName;
									maintainItem.FilterPartTypeID = maintainItem.HisFilterPartTypeID;
									maintainItem.FilterPartID = maintainItem.HisFilterPartID;
									maintainItem.FilterPartNum = maintainItem.HisFilterPartNum;
									maintainItem.FilterPartName = maintainItem.HisFilterPartName;
									maintainItem.FilterPartPrice = 0;
								}
								if (res.cancel) {
									maintainItem.IsReplaceFilterPart = true;
								}
								this.AggregateMaintainPartData(woProItem);
							}
						});
					}

				}

			},


			ChangeMaintenance(index, e) {
				let productItem = this.orderDetailData.WoProuduct[index];
				productItem.maintenanceIndex = e.detail.value;
			},
			onOpenAccoountClaimDate(e) {
				console.log(this.$refs);
				this.$refs.AccoountClaimDate.open();
			},
			confirmAccoountClaimDate(e) {
				this.CustomerRequiresMaintenanceDate = e.fulldate;
				console.log(this.CustomerRequiresMaintenanceDate);
			},
			onOpenPurchaseDate(index, e) {
				let proItem = this.orderDetailData.WoProuduct[index];
				if (!proItem.IsProductConfirmed) {
					this.$refs.PurchaseDate[index].open();
				} else {
					uni.showToast({
						title: "产品已确认，不能选择保修时间",
						icon: "none"
					});
				}
			},

			//保修时间
			confirmPurchaseDate(index, e) {
				console.log("时间", e);
				let prodItem = this.orderDetailData.WoProuduct[index];
				console.log("产品", prodItem.ProductId);
				//debugger;
				// 产品确认为 false
				if (!prodItem.IsProductConfirmed) {
					if (prodItem.ProductMaintainData != null && prodItem.ProductMaintainData.length > 0) {
						uni.showModal({
							title: '购机日期更改确认',
							content: '是否确认修改购机日期？将会更新保养信息行！',
							success: (res) => {
								if (res.confirm) {
									prodItem.PurchaseDate = e.fulldate;
									this.GetMaintainInfoFromServer(prodItem, index);
								}
							},
						});
					} else {
						prodItem.PurchaseDate = e.fulldate;
						this.GetMaintainInfoFromServer(prodItem, index);
					}
					console.log(index);
				} else {
					uni.showToast({
						title: "产品已确认",
						icon: "none"
					});
				}
			},

			//扫描物流码
			onOpenQrcode(index, e) {
				let prodItem = this.orderDetailData.WoProuduct[index];
				if (prodItem.IsProductConfirmed == true) {
					uni.showToast({
						title: "产品已确认,不能输入物流码",
						icon: "none"
					});
				} else {
					// 调起条码扫描
					uni.scanCode({
						scanType: 'barCode',
						success: (res) => {
							//console.log('条码类型：' + res.scanType);
							//console.log('条码内容：' + res.result);
							prodItem.Barcode = res.result;
							uni.showLoading({
								mask: true,
							})
							this.BarcodeValidCheckAsync(index, prodItem.Barcode)
								.then((succ) => {
									let data = succ;
									this.RefreshProduct(data, index, prodItem.Barcode);
								}, (err) => {
									uni.hideLoading();
									uni.showToast({
										title: "物流码验证失败",
										icon: "none",
										duration: 3000
									});
								});
						}
					});
				}
			},

			//物流码
			onBlurLogisticsCode(index, e) {
				//console.log(e);
				if (e.detail.value) {
					let productItem = this.orderDetailData.WoProuduct[index];
					let strOriBarcode = e.detail.value;
					let strBarcode = productItem.Barcode;
					//debugger;
					if (strOriBarcode != strBarcode) {
						uni.showLoading({
							mask: true,
						})
						this.BarcodeValidCheckAsync(index, strOriBarcode)
							.then((succ) => {
								let data = succ;
								this.RefreshProduct(data, index, strOriBarcode);
							}, (err) => {
								uni.hideLoading();
								uni.showToast({
									title: "物流码验证失败",
									icon: "none",
									duration: 2000
								});
							});
					}
				}
			},

			//产品
			onOpenSearch(index) {
				let prodItem = this.orderDetailData.WoProuduct[index];
				//console.log(prodItem.IsProductFill)
				if (!prodItem.IsProductConfirmed) {
					if (prodItem.ProductMaintainData != null && prodItem.ProductMaintainData.length > 0) {
						uni.showModal({
							title: '产品更改确认',
							content: '是否确认修改产品信息？将会重置保养信息行！',
							success: (res) => {
								if (res.confirm) {
									this.productMaintainData.splice(index, 1);
									uni.navigateTo({
										url: `../../productlist/index?action=selectproduct&prodIndex=${index}`
									});
								}
							},
						});
					} else {
						uni.navigateTo({
							url: `../../productlist/index?action=selectproduct&prodIndex=${index}`
						});
					}
				} else {
					uni.showToast({
						title: "产品已确认,不能选择产品",
						icon: "none",
						mask: true,
						duration: 800
					})
				}
			},

			//确认产品
			onAffirmProduct(e) {
				uni.showLoading({
					title: "确认产品中..",
					mask: true,
				})
				this.AffirmProduct(e);
				//console.log("确认产品");
			},

			//取消
			onCancel(e) {
				uni.showModal({
					title: "取消确认",
					content: "您是否放弃提交当前的完工信息？",
					success: function(res) {
						if (res.confirm) {
							uni.navigateBack();
						}
					},
				})
			},
			//水质检测
			saveWaterQuality(index, e) {
				//console.log(e);
				let proItem = this.orderDetailData.WoProuduct[index];
				let formData = e;
				proItem.NewChlorine = formData.NewChlorinetxt;
				proItem.NewHardness = formData.NewHardnesstxt
				proItem.NewTDS = formData.NewTDStxt
				proItem.OriChlorine = formData.OriChlorinetxt
				proItem.OriHardness = formData.OriHardnesstxt
				proItem.OriTDS = formData.OriTDStxt
				proItem.OriTemperature = formData.OriTemperaturetxt
				proItem.IsWaterAnalysis = true;
				proItem.isShowWaterAnalysisAddBtn = false;
				this.$refs.waterQuality[index].closePoPup();
				//console.log(this.orderDetailData.WoProuduct[index]);
			},
			//打开水质检测
			onOpenWaterQualityPopup(index, e) {
				// let productItem = this.orderDetailData.WoProuduct[index]
				// this.$refs.proItem = productItem;
				// this.$refs.fieldReq = this.ParseWaterAnalysisFieldRequired(productItem.WaterAnalysisFieldRequired);
				this.$refs.waterQuality[index].openPoPup();
			},
			//移除水质检测
			onCanleWaterQuality(e) {
				let productItem = this.orderDetailData.WoProuduct[e];
				uni.showModal({
					title: "操作确认",
					content: "确认删除水质检测信息？",
					success: function(res) {
						if (res.confirm) {
							productItem.OriTDS = "";
							productItem.OriTemperature = "";
							productItem.OriHardness = "";
							productItem.OriChlorine = "";
							productItem.NewTDS = "";
							productItem.NewHardness = "";
							productItem.NewChlorine = "";
							productItem.isShowWaterAnalysisAddBtn = true;
							productItem.isWaterAnalysis = false;
						}
					}
				});
			},
			//实际收款总金额
			onChangeActualReceiptAmount(e) {
				console.log(e);
				this.ActualReceiptAmount = e;
			},
			//完工备注
			onChangeOrderRremark(e) {
				this.OrderRremark = e.detail.value;
			},
			onSumbit(e) {
				this.SubmitOrder();
			}
		}
	}
</script>

<style lang="scss">
	@import '../index.scss';
</style>
